package com.xxx.controller;


import com.xxx.pojo.Admin;
import com.xxx.pojo.RespBean;
import com.xxx.pojo.Role;
import com.xxx.service.IAdminService;
import com.xxx.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  系统管理员设定部门管理员以及权限
 * </p>
 *
 * @author WXH
 * @since 2022-02-23
 */
@RestController
@RequestMapping("/system/admin")
@Api(value = "部门管理员",tags = "部门管理员")
public class AdminController {
    @Autowired
    private IAdminService adminService;
    @Autowired
    private IRoleService roleService;
    private Integer adminId;
    private List<Integer> rids;


    @ApiOperation(value = "获取所有部门管理员")
    @GetMapping("/list")
    public List<Admin> getAllAdmins(String keywords){
        return adminService.getAllAdmins(keywords);
    }
    @ApiOperation(value = "更新操作员")
    @PutMapping("/update")
    public RespBean updateAdmin(@RequestBody Admin admin){
        if (adminService.updateById(admin)){
            return RespBean.sucess("更新成功!!");
        }
        return RespBean.error("更新失败");
    }
    @ApiOperation(value = "删除部门管理员(操作员)")
    @DeleteMapping("/delete")
    public RespBean deleteAdmin(Integer id){
        if(adminService.removeById(id)){
            return RespBean.sucess("删除成功!!");
        }
        return RespBean.error("删除成功");
    }
    @ApiOperation(value = "获取所有操作员角色")
    @GetMapping("/getroles")
    public List<Role> getAllRoles(){
        return roleService.list();
    }
    @ApiOperation(value = "更新操作员角色")
    @PutMapping("/updaterole")
    public RespBean updateAdminRole(@RequestParam("adminId") Integer adminId,
                                    @RequestParam("rids") List<Integer> rids){

        return adminService.updateAdminRole(adminId,rids);
    }



}
